package gqz.mvvm.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.GridView;

import java.util.ArrayList;

import gqz.mvvm.BR;
import gqz.mvvm.R;
import gqz.mvvm.model.ItemString;
import gqz.mvvm.adapter.MyBaseAdapter;

/**
 * Created by Administrator on 2017/12/4.
 */

public class GridViewActivity extends BaseActivity implements MyBaseAdapter.MyItemClickListener {

    private MyBaseAdapter<ItemString> adapter;

    private ArrayList<ItemString> data = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid);

        adapter = new MyBaseAdapter<>(this, R.layout.item_listview, data, BR.txt, this);
        GridView gv = (GridView) findViewById(R.id.grid_gridview);
        gv.setAdapter(adapter);

        for (int i = 0; i < 100; i++) {
            data.add(new ItemString("item " + i));
        }
    }

    @Override
    public void onItemClick(View view) {
        int pos = (int) view.getTag();
        Log.v("GridViewActivity", "onItemClick: " + pos);
    }
}
